#ifndef __MY_GEODETIC
#define __MY_GEODETIC
#include <Global/pack1.h>

PRESTRUCT( MVModule );
PRESTRUCT( MVMainInfo );
PRESTRUCT( MVMapSource );

#include "i_Types.h"
#include "i_ControlList.h"
#include "i_Handler.h"
#include "i_PosSrc.h"
#include "i_Map.h"
#include "i_Plugins.h"
#include "i_OziMap.h"

class HTitleSave {
    class CaptionAccess : public TControl {
      public:
        __property Caption;
    };
    AnsiString     s;
    CaptionAccess *w;
  public:
    HTitleSave( TControl *ctl ) { w = (CaptionAccess*)ctl; s = w->Caption; }
    ~HTitleSave()               { w->Caption = s; }
};

// [logs.cpp]
HDECLSPEC void         MYRTLEXP GD_Init( TForm *Owner, PHLogComboBox lList, PHCfgStorage cfg );
HDECLSPEC void         MYRTLEXP GD_Shutdown( void );

HDECLSPEC PHOperation  MYRTLEXP RTGetOperation( void );
HDECLSPEC PPRPeriod    MYRTLEXP RTGetIdlePeriod( void );

class HRop {
   PHOperation op;
  public:
    __fastcall HRop( void )          { op = RTGetOperation(); op->IncShow(); }
    __fastcall HRop( PHOperation p ) { op = p; if (op) op->IncShow(); }
    __fastcall ~HRop()               { if (op) op->SetText(NULL); }

   PHOperation operator->() { return op; }

   void Close( void ) { if (op) { op->SetText(NULL); op = NULL; } }
};

HDECLSPEC int             MYRTLEXP_PT RTLog( CONSTSTR msg,... );
HDECLSPEC int             MYRTLEXP    RTLogV( CONSTSTR msg,va_list a );
HDECLSPEC int             MYRTLEXP_PT RTLogR( CONSTSTR msg,... );
HDECLSPEC int             MYRTLEXP    RTLogRV( CONSTSTR msg,va_list a );
HDECLSPEC void            MYRTLEXP_PT RTErrorMessage( HWND w,CONSTSTR fmt,... );
HDECLSPEC void            MYRTLEXP    RTErrorMessageV( HWND w,CONSTSTR fmt,va_list a );
HDECLSPEC void            MYRTLEXP_PT RTSayMessage( HWND w,CONSTSTR fmt,... );
HDECLSPEC void            MYRTLEXP    RTSayMessageV( HWND w,CONSTSTR fmt,va_list a );

// [infos.cpp]
HDECLSPEC int             MYRTLEXP GD_DatumCount( void );
HDECLSPEC CONSTSTR        MYRTLEXP GD_DatumName( int idx );
HDECLSPEC int             MYRTLEXP GD_CoordCount( void );
HDECLSPEC CONSTSTR        MYRTLEXP GD_CoordName( Coordinate_Type idx );
HDECLSPEC int             MYRTLEXP GD_DegTypeCount( void );
HDECLSPEC CONSTSTR        MYRTLEXP GD_DegTypeName( int idx );
inline    CONSTSTR                 GD_CoordName( int idx )        { return GD_CoordName( (Coordinate_Type)idx ); }
inline    CONSTSTR                 GD_DegTypeName( degTypes idx ) { return GD_DegTypeName( (int)idx ); }
HDECLSPEC int             MYRTLEXP OziDatum2Datum( CONSTSTR nm );  //Ret -1 if not found
HDECLSPEC Coordinate_Type MYRTLEXP OziProjection2CoordSys( CONSTSTR m );

// [cvt.cpp]
HDECLSPEC void            MYRTLEXP ToDMS( double x, int& g, int& m, double& s );
HDECLSPEC void            MYRTLEXP ToDM( double x, int& g, double& m );
HDECLSPEC double          MYRTLEXP FromDMS( int d, int m, double s );
HDECLSPEC double          MYRTLEXP FromDM( int d, double m );

HDECLSPEC void            MYRTLEXP FullX2X( double& x, char& S, bool isX );
HDECLSPEC double          MYRTLEXP X2FullX( double x, char S, bool isX );
HDECLSPEC double          MYRTLEXP Str2LatLon( CONSTSTR d, CONSTSTR m /*NULLs*/, CONSTSTR s/*NULLs*/, char S, bool isX );  //Uses Abort() on error
HDECLSPEC CONSTSTR        MYRTLEXP FmtDouble( double v, int nF, int nR );                               //ret stat buff with "%*.*lf"
HDECLSPEC bool            MYRTLEXP Val2Double( CONSTSTR m,double& v );
HDECLSPEC double          MYRTLEXP Val2DoubleErr( CONSTSTR m );         //Uses Abort()
HDECLSPEC bool            MYRTLEXP BoundCoordStrX( char *str, double x );
HDECLSPEC bool            MYRTLEXP BoundCoordStrY( char *str, double x );
HDECLSPEC CONSTSTR        MYRTLEXP Coord2Str( char *str, double x, degTypes type, bool isX );

// [utils.cpp]
HDECLSPEC pchar           MYRTLEXP STrim( char *str );              //Trim all spaces from string
HDECLSPEC pchar           MYRTLEXP SCol( const char *m, int num );  //Get trimmed string column with "," delimiter
HDECLSPEC MyString        MYRTLEXP TimeDiff2TimeStr( const CMP_TIME_TYPE& diff );
HDECLSPEC bool            MYRTLEXP CheckTerminationMessages( HWND wnd );
HDECLSPEC void            MYRTLEXP DoPopupMenu( TControl *sb, int x, int y, TPopupMenu *mnu );
HDECLSPEC bool            MYRTLEXP HSelectDirectory( AnsiString& dir, bool AllowCreate );
HDECLSPEC BOOL            MYRTLEXP CreateFullDirectory( char *nm );
HDECLSPEC GCoord_t        MYRTLEXP GMax( const GCoord_t& v, const GCoord_t& v1 );
HDECLSPEC GCoord_t        MYRTLEXP GMin( const GCoord_t& v, const GCoord_t& v1 );

//---------------------------------------------------------------------------
// COORDS
//---------------------------------------------------------------------------
// [coords.cpp]
#define GD_STATE_ERROR     0x0001
#define GD_STATE_WARNING   0x0002

inline bool GD_IsError( DWORD v )   { return IS_FLAG(v,GD_STATE_ERROR); }
inline bool GD_IsWarning( DWORD v ) { return IS_FLAG(v,GD_STATE_WARNING); }
inline bool GD_IsOk( DWORD v )      { return v == 0; }

/* NOTES:
   Geodetic coords must be:
     x: [-180..180]
     y: [-90..90]
*/
HDECLSPEC DWORD           MYRTLEXP CVT_GetState( void );
HDECLSPEC bool            MYRTLEXP CVT_Coord2Coord( const Coordinate_Tuple& sgc, const Parameter_Tuple& sgp, Coordinate_Type scs, int sdn,
                                                    Coordinate_Tuple& dgc, Parameter_Tuple& dgp, Coordinate_Type dcs, int ddn );

HDECLSPEC bool            MYRTLEXP CVT_G2Any( const GPoint& gp, Coordinate_Type cs, int dn,
                                              PMVProjectionInfo pr/*=NULL*/, OZIMapPoint& op );
HDECLSPEC bool            MYRTLEXP CVT_Any2G( const OZIMapPoint& op, Coordinate_Type cs, int dn,
                                              PMVProjectionInfo pr/*=NULL*/, GPoint& gp );
HDECLSPEC bool            MYRTLEXP CVT_LatLon2Any( double x, double y,
                                                   Coordinate_Type cs, int dn,
                                                   PMVProjectionInfo pr, OZIMapPoint& op );

HDECLSPEC bool            MYRTLEXP CVT_G2NE( const GPoint& p, Coordinate_Type cs, int dn, PMVProjectionInfo pr, MyPoint& gp );
HDECLSPEC bool            MYRTLEXP CVT_NE2G( int x, int y, Coordinate_Type cs, int dn, PMVProjectionInfo pr, GPoint& gp );

HDECLSPEC bool            MYRTLEXP CVT_LatLon2G( double x, double y, int dn,
                                                 PMVProjectionInfo pr /*=NULL*/, GPoint& gp );
HDECLSPEC bool            MYRTLEXP CVT_G2LatLon( const GPoint& p, int dn, PMVProjectionInfo pr, double& x, double& y );

HDECLSPEC CONSTSTR        MYRTLEXP CVT_Coord2Str( char *buff, size_t sz,
                                                  const Coordinate_Tuple& sgc, const Parameter_Tuple& sgp, Coordinate_Type scs, int sdn,
                                                  PMVProjectionInfo pr/*=NULL*/, Coordinate_Type dcs, int ddn, degTypes dt, char *dlm );
HDECLSPEC CONSTSTR        MYRTLEXP CVT_G2CoordsStr( char *buff, size_t bsz,
                                                    const GCoord_t& x, const GCoord_t& y,
                                                    PMVProjectionInfo pr/*=NULL*/, Coordinate_Type cs, int dn, degTypes dt, char *dlm );

HDECLSPEC void            MYRTLEXP CorrectG( GCoord_t& x, GCoord_t& y );
HDECLSPEC void            MYRTLEXP CorrectDatumG( int Datum, GCoord_t& x, GCoord_t& y );

//---------------------------------------------------------------------------
// GUI UTILS
//---------------------------------------------------------------------------
//[f_DatumSelect.cpp]
HDECLSPEC bool            MYRTLEXP SelectDatum( TForm *Owner, int& Datum );
//[f_AskCoord.cpp]
HDECLSPEC bool            MYRTLEXP AskPosition( TForm *Parent, GPoint& pos );

//---------------------------------------------------------------------------
// DATA
//---------------------------------------------------------------------------
HDECLSPEC PHStorageLink MYRTLEXP Opt;

#define GOPT( nm, v )    Opt->Read( nm, v )
#define SOPT( nm, v )    Opt->Write( nm, v )
#define OPT_KEY( nm )    Opt->SubKey( nm )

#define COL( n )         STrim( (char*)StrGetCol( m, n, "," ))

#define LNG              TranslatePSTR
#define SLNG( v )        TranslateSTR( v ).c_str()
#define _L( v )          v

#include <Global/pop.h>
#endif